import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class StoreStuff extends JFrame implements ActionListener{
	Store store;
	JPanel mainpanel;
	JOptionPane pop;
	JButton petadd;
	JLabel name;
	JTextField nameenter;
	JLabel type;
	JTextField typeenter;
	JLabel age;
	JTextField ageenter;
	JSeparator sep;
	JLabel output;
	public StoreStuff(){
		store = new Store();
		setTitle("Hello");//top of screen title
		setSize(500,500);//size of screen
		setDefaultCloseOperation(EXIT_ON_CLOSE);//closes 
		SetUpPanel();
		this.add(mainpanel);
	}
	public void SetUpPanel(){
		mainpanel = new JPanel();
		sep = new JSeparator();
		output = new JLabel();
		name = new JLabel("Name: ");
		nameenter = new JTextField();
		age = new JLabel("Age: ");
		ageenter = new JTextField();
		type = new JLabel("Type: ");
		typeenter = new JTextField();
		petadd = new JButton("Add Pet");
		GridLayout layout = new GridLayout(15,1);
		mainpanel.setLayout(layout);
		mainpanel.add(name);
		mainpanel.add(nameenter);
		mainpanel.add(age);
		mainpanel.add(ageenter);
		mainpanel.add(type);
		mainpanel.add(typeenter);
		mainpanel.add(petadd);
		petadd.addActionListener(this);
		mainpanel.add(sep);
		mainpanel.add(output);
	}
	public static void main(String[] args) {
		StoreStuff hello = new StoreStuff();//create instance of the function
		hello.setVisible(true);//makes visible
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String animal = nameenter.getText();
		Integer agee = Integer.parseInt(ageenter.getText());
		String species = typeenter.getText();
		if (species.compareTo("Prime")==0||species.compareTo("prime")==0){
			store.addPet(new Prime(agee, animal, true));
			output.setText(animal + " (" + species + ") " + agee);
		}
		else if (species.compareTo("Cat")==0||species.compareTo("cat")==0){
			store.addPet(new Cat(agee, animal, true));
			output.setText(animal + " (" + species + ") " + agee);
		}
		else{
			output.setText("That's not an animal!");
		}
	}
}
